<template>
  <div class="addExpert">
    <!--导航-->
    <tmpHeader :index='4'/>
    <h2 style="text-align:center;font-weight:600;margin-bottom:10px;color: #333">严选专家编辑</h2>
    <div class="main_expert">
      <p class="title">专家基本信息</p>
      <Row gutter="24" class="box">
        <Col span="8">
          <!--专家姓名-->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">*</span>
              <span>医生姓名：</span>
            </div>
            <Input v-model="name" placeholder="空" style="width: 500px" disabled/>
          </div>
          <!--机构名称-->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>所属机构：</span>
            </div>
            <Input v-model="yname" placeholder="空" style="width: 500px" disabled/>
          </div>
          <!-- 是否为专家 -->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>专家标识：</span>
            </div>
            <iSwitch size="large"  v-model="switch2" @on-change="changeStatus(switch2)">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
            </iSwitch>
          </div>
        </Col>
        <Col span="8">
          <!--医生性别-->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>医生性别：</span>
            </div>
            <Input v-model="gender" placeholder="空" style="width: 500px" disabled/>
          </div>
          <!--专家科室-->
          <div class="main_expert_experts">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>所属科别：</span>
            </div>
            <div class="iselected">
              <Select v-model="keshi" style="width:200px;margin-right:10px" disabled>
                <Option :value="keshi" :key="keshi">{{ keshi }}</Option>
              </Select>
            </div>
          </div>
          <!--显示-->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>是否在公众端显示：</span>
            </div>
            <iSwitch size="large"  v-model="switch1" @on-change="change" :disabled="switch1Disable">
                <span slot="open">开启</span>
                <span slot="close">关闭</span>
            </iSwitch>
          </div>
        </Col>
        <Col span="8">
          <!--联系电话-->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>联系电话：</span>
            </div>
            <Input v-model="phone" placeholder="空" style="width: 500px" disabled/>
          </div>
          <!--职务-->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>医师职称：</span>
            </div>
              <Select v-model="zhiwu" style="width:200px" disabled>
                <Option :value="zhiwu" :key="zhiwu">{{ zhiwu }}</Option>
                <!-- <Option
                  v-for="(item) in doctorList"
                  :value="item.value"
                  :key="item.value"
                >{{ item.value }}</Option> -->
              </Select>
              <!-- 职务 -->
            <!-- <Input v-model="post" placeholder="" style="width: 500px" disabled/> -->
          </div>
          <!--排序-->
          <div class="main_expert_item">
            <div class="main_expert_title">
              <span style="color:red;">&nbsp;&nbsp;</span>
              <span>列表排序：</span>
            </div>
            <InputNumber :max="99999" :min="1" v-model.trim="isort" style="width: 100px" placeholder="无"></InputNumber>
            <small style="margin-left:10px;color:#FF9966">备注:只能填写数字,1代表置顶以此类推</small>
          </div>
        </Col>
      </Row>
    </div>
    <div class="main_expert">
      <p class="title">专家附属信息</p>      
      <Row gutter="24" class="box">
        <Col span="12">
          <!--专业特长-->
          <div class="main_expert_inputi">
            <div class="main_expert_title">
              <span style="color:red;">*</span>
              <span>专业特长：</span>
            </div>
            <div class="shuru">
              <Input v-model="doctorGood" type="textarea" :rows="6" placeholder="专家专业特长" disabled class="text" />
            </div>
          </div>
        </Col>
        <Col span="12">
          <!--个人简介-->
          <div class="main_expert_inputi">
            <div class="main_expert_title">
              <span style="color:red;">*</span>
              <span>个人简介：</span>
            </div>
            <div class="shuru">
              <Input v-model="personalIntroduction" type="textarea" :rows="6" placeholder="请输入个人简介" disabled class="text" />
            </div>
          </div>
        </Col>
      </Row>
    </div>
    <!--保存-->
    <div class="expert_save">
      <Button type="primary" @click="save" style="width:75px;height:35px;">
        <Icon type="ios-checkmark" style="margin-right: 5px" />保存
      </Button>
      <Button @click="back" style="width:75px;height:35px;">
        <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
      </Button>
    </div>
  </div>
</template>

<script>
import tmpHeader from "@/pages/organizat/contentmen/tmpHeader";
import api from "@/api/commonApi";
export default {
  components: {
    tmpHeader
  },
  data() {
    return {
      id: "tinymce-editor",
      id1: "tinymce-editor1",
      height: 200,
      tinymceHtml: "",
      switch1: false,
      switch1Disable: false,   ////禁止公众端显示点击
      name: "",
      yname: "",
      keshi: "",
      gender: "",
      phone:"",
      zhiwu: "",
      isort: "",
      personalIntroduction: "",
      doctorGood: "",
      post: "",
      switch2: false,
      doctorList: [
        {
          value: "主任医师"
        },
        {
          value: "副主任医师"
        },
        {
          value: "住院医师"
        },
        {
          value: "主治医师"
        }
      ]
    };
  },
  created(){
    if(this.switch2 ==  false){
      this.switch1 =  false
      this.switch1Disable = true
    } else {
        this.switch1Disable = false           
    }
    let breadList = [
            { path: "/index", title: "首页" },
            {
                path: "/index/operation/mechanism/index",
                title: "机构运营"
            },
            {
                path: "/index/operation/home",
                title: "机构配置管理"
            }
        ];
        this.$emit("changeBreadList", breadList);
        this.status();
  },
  mounted() {
    let data = this.$route.params.item;
    console.log(data)
    if (data) {
      this.name = data.name;
      this.yname = data.hospitalname;
      this.personalIntroduction = data.personalIntroduction;
      this.doctorGood = data.doctorGood;
      if(data.gender == 2){
        this.gender = '女'
      } else if(data.gender == 1){
        this.gender = "男";
      } else if(data.gender == 9){
        this.gender = "其他";
      }
      this.phone = data.phone;
      this.zhiwu = data.titleName;
      this.post = data.post;
      this.keshi = data.deptName;
      this.isort = data.sort;
      if(data.display=='否'){
        data.display = 0
      }else{
        data.display = 1
      }
      this.switch1 = Boolean(data.display);
      this.switch2 = Boolean(data.iexpert);
      if(this.switch2 == true){
        this.switch1Disable = false 
      }
    }
  },
  methods: {
    //根据专家标识状态控制公众端按钮点击情况
    changeStatus(val){
      if(val == false){
          this.switch1 =  false
          this.switch1Disable = true              
      } else {
          this.switch1Disable = false           
      }
    },
    status() {
      let flag = localStorage.getItem("status");
      if (!Boolean(flag)) {
        this.$Message.info("您还没有开通互联网医院,去开通");
        this.flag = true;
        localStorage.setItem("homeIndex", 0);
        setTimeout(() => {
          this.functionJS.paramsNavgationTo(this, "homeinfo", {
            // 公用方法
          }); 
        }, 600);
      }
    },
    isorts() {
      if (this.isort <= 0) {
        this.isort = "";
        this.$Message.info("排序置顶为1");
      }
    },
    //显示按钮
    change(status) {
      // this.$Message.info('开关状态：' + status);
    },
    back() {
      let pageNo = this.$route.params.pageNo;
      this.functionJS.paramsNavgationTo(this, "expertList", {
        // 公用方法
          pageNo
      }); 
    },
    save() {
      let hospitalId = sessionStorage.getItem("hospitalId");
      let doctorId = this.$route.params.item.id;
      let params = {
        // 显示
        display: Number(this.switch1),
        //排序
        sort: this.isort,
        // 职务
        post: this.post,
        id: doctorId,
        hospitalId,
        iexpert: Number(this.switch2)
      };
      if (params.name == "") {
        this.$Message.error("专家姓名不能为空");
        this.disabledSave = false
      } else {
        this.$axios.post(api.updateDoctorById, params).then(res => {
          if (res.data.success) {
            let pageNo = this.$route.params.pageNo;
            this.$Message.info("修改成功");
            setTimeout(() => {
              this.functionJS.paramsNavgationTo(this, "expertList", {
                // 公用方法
                  pageNo
              }); 
            }, 500);
          } else {
            this.$Message.error("修改失败请重试");
            this.disabledSave = false
          }
        });
      }
    }
  }
};
</script>

<style scoped lang="less">
.addExpert {
  width: calc(100% - 20px);
  padding: 10px 30px;
  margin: 0 auto;
  background: #fff;
  .main_expert {
    width: 98%;
    display: flex;
    flex-direction: column;
    margin: 10px auto;
    border: 1px solid #f0f0f0;
    box-shadow: 0 4px 3px #ebedf8;
    border-radius: 5px;
    margin-bottom: 20px;
    .box{
      padding: 0 20px;
    }
    .title {
      font-size: 20px;
      padding-left: 15px;
      margin-bottom: 20px;
      color: #333;
      height: 40px;
      line-height: 40px;
      background: #ebedf8;         
    }
    .main_expert_item {
      display: flex;
      flex-direction: row;
      height: 50px;
      align-items: center;
      .main_expert_title {
        min-width: 100px;
      }
      input {
        display: inline-block;
        width: 400px;
        height: 30px;
        outline: none;
        text-indent: 5px;
      }
      button {
        width: 60px;
        height: 30px;
        border-radius: 10px;
        margin-left: 20px;
        border: none;
        outline: none;
        background: #5362e1;
        color: #fff;
      }
    }
    .main_expert_experts {
      display: flex;
      flex-direction: row;
      height: 50px;
      align-items: center;
      .main_expert_title {
        min-width: 100px;
      }
      .iselected {
        select {
          width: 150px;
        }
        span {
          display: inline-block;
          margin: 0 20px;
        }
      }
    }
    .main_expert_inputi {
      display: flex;
      flex-direction: row;
      margin: 10px 0;
      .main_expert_title {
        min-width: 100px;
      }
      .shuru {
        width: 100%;
        textarea {
          text-indent: 1em;
          width: 100%;
          height: 150px;
        }
      }
    }
  }
  .expert_save {
    width: 100%;
    margin: 20px auto;
    text-align: center;
  }
}
</style>